<template>
  <div class="chart-box">
    <Bar class="chart" :loading="loadingRef" :chartData="chartData" title="与上个周期数据对比" />
  </div>

</template>
<script lang="ts"
  setup>
  import { ref } from 'vue';
  import { getYoyData } from '@/api/dataReport/energyStatistics'
  import Bar from '@/components/Charts/Bar/index.vue'

  const loadingRef = ref(false)
  const chartData = ref({
    xaxisList: [],
    yaxisList: [],
  })

  const getData = (searchInfo) => {
    loadingRef.value = true;
    getYoyData(searchInfo).then(e => {
      console.log(e);
      
      chartData.value = e
    }).catch(e => {
      chartData.value = {
        xaxisList: [],
        yaxisList: [],
      }
    }).finally(() => {
      loadingRef.value = false;
    })
  }

  defineExpose({//对外暴露
    getData
  })

</script>
